package com.topscore.uke.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.RelativeLayout;

import com.topscore.uke.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 71468 on 2017/11/7.
 */

public class PictureSingleSelector extends Dialog implements View.OnClickListener {
    @Bind(R.id.select_from_camera)
    RelativeLayout selectFromCamera;
    @Bind(R.id.select_from_gallery)
    RelativeLayout selectFromGallery;
    @Bind(R.id.cancel_btn)
    RelativeLayout cancelBtn;

    private PictureSelectedListener mSelectedListener;

    public PictureSingleSelector(@NonNull Context context, PictureSelectedListener selectedListener) {
        super(context);
        this.mSelectedListener = selectedListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();

        window.setWindowAnimations(R.style.DialogBottomAnimation);
        window.setGravity(Gravity.BOTTOM);
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setContentView(R.layout.picture_single_selector_layout);
        ButterKnife.bind(this);
        initViews();
    }

    private void initViews() {
        cancelBtn.setOnClickListener(this);
        selectFromCamera.setOnClickListener(this);
        selectFromGallery.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.select_from_camera:
                mSelectedListener.onSelectFromCamera();
                dismiss();
                break;

            case R.id.select_from_gallery:
                mSelectedListener.onSelectFromGallery();
                dismiss();
                break;

            case R.id.cancel_btn:
                dismiss();
                break;
        }
    }

    public interface PictureSelectedListener {
        void onSelectFromCamera();

        void onSelectFromGallery();
    }
}
